package streamer.webapp.action;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import org.primefaces.model.DefaultTreeNode;
import streamer.webapp.displaybeans.TreeBean;

/**
 * Common class for any web action.
 *
 */
public abstract class AbstractWebAction implements Serializable{
	
	private static final long serialVersionUID = 7057527719243346590L;

	private DefaultTreeNode selectedNode;
	
	@ManagedProperty(value = "#{treeBean}")
	protected TreeBean treeBean;
	
	/**
	 * Get the current faces view.
	 * @return the UI view root component
	 */
	protected UIViewRoot getCurrentFacesView() {
		return FacesContext.getCurrentInstance().getViewRoot();
	}
	
	protected void displayMessage(FacesMessage.Severity severity, String title, String message) {
		FacesMessage msg = new FacesMessage(severity, title, message);
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

	public TreeBean getTreeBean() {
		return treeBean;
	}

	public void setTreeBean(TreeBean treeBean) {
		this.treeBean = treeBean;
	}

	public void setSelectedNode(DefaultTreeNode selectedNode) {
		this.selectedNode = selectedNode;
	}

	public DefaultTreeNode getSelectedNode() {
		return selectedNode;
	}
}
